﻿using System;
using System.Collections.Generic;
using System.Text;
using Barbar.MapReport.Common;

namespace Barbar.MapReport.DataSource.Query {
  public class RegionContainsPoint : RegionCriteria {
    private GeoPoint m_Point;
    private int m_GoogleZoomLevel;

    public GeoPoint Point {
      get { return m_Point; }
      set { m_Point = value; }
    }

    public int GoogleZoomLevel {
      get { return m_GoogleZoomLevel; }
      set { m_GoogleZoomLevel = value; }
    }

    public RegionContainsPoint(IGeoPoint point)
      : this( point, ZoomLevelCollection.MaxGoogleZoomLevel) {
    }

    public RegionContainsPoint(IGeoPoint point, int googleZoomLevel) {
      m_Point = new GeoPoint(point);
      m_GoogleZoomLevel = googleZoomLevel;
    }

    internal override bool Evaluate(Region region) {
      ZoomLevel zoomLevel = DataSourceManager.ZoomLevels.GetZoomLevel(m_GoogleZoomLevel);
      Polygon polygon = DataSourceManager.GetRegionGeometry(region.Id, zoomLevel);
      return polygon.ContainsPoint(m_Point);
    }
  }
}
